#!/usr/bin/python
# -*- coding: utf-8 -*-
# @version        : 1.0
# @Create Time    : 2024/9/6 11:11
# @File           : __init__
# @IDE            : PyCharm
# @desc           : 描述
from sqlalchemy import distinct, select
from sqlalchemy.ext.asyncio import AsyncSession
from core.crud import DalBase
from . import models, schemas


class SampleGroupDal(DalBase):

    def __init__(self, db: AsyncSession):
        super(SampleGroupDal, self).__init__()
        self.db = db
        self.model = models.DCSampleGroup
        self.schema = schemas.SampleGroupSimpleOut

    async def get_select_datas(self):
        sql = select(distinct(self.model.group_name))
        queryset = await self.db.scalars(sql)
        return [{'value': i, 'label': i} for i in queryset.all()]
        # schemas.SampleGroupOptionsOut.model_validate(i).model_dump()

    async def get_group(self, group_name: str, quantity: int):
        return await self.get_data(group_name=group_name, min_value=('<=', quantity), max_value=('>=', quantity), is_active=True, v_return_none=True)


class SampleStandardDal(DalBase):

    def __init__(self, db: AsyncSession):
        super(SampleStandardDal, self).__init__()
        self.db = db
        self.model = models.DCSampleStandard
        self.schema = schemas.SampleStandardSimpleOut
